<template>
	<view class="myOrder">
		<u-sticky bgColor="#fff">
			<u-tabs
				:current="current"
				:scrollable="false"
				:list="tabNav"
				@click="clickTab"
				inactiveStyle="font-size: 24rpx;"
				lineColor="#E54E4E"
				itemStyle="height: 88rpx;font-weight: bold;"
			></u-tabs>
		</u-sticky>
		<view class="container">
			<j-orderList nbtn tg liststyle="1" :list="list" @btns="clickbtn"></j-orderList>
			<u-loadmore :status="status" />
		</view>
		
	</view>
</template>

<script>
import API from '@/common/api';
export default {
	name: 'myOrder',
	data() {
		return {
			current: 0,
			status: '',
			tabNav: [
				{
					name: '全部',
				},
				{
					name: '本人推广'
				},
				{
					name: '下级推广'
				}
			],
			list: [],
			paging: {
				page: 1,
				pagenum: 10
			},
		};
	},
	onLoad(data) {
		if (data.hasOwnProperty('current')) {
			this.current = Number(data.current);
		}
		this.reset();
		this.init();
	},
	onShow() {
	},
	onReachBottom() {
		if (this.status === 'nomore') return;
		this.init();
	},
	methods: {
		init(status = 0) {
			this.status = 'loading';
			API.getJson('users_fansOrders', { type:this.current, ...this.paging }).then((res) => {
				const { code, data, message } = res;
				if (code === 1) {
					if (data.length !== 0) this.list = this.list.concat(data);
					if (this.paging.pagenum === data.length) {
						this.paging.page += 1;
						this.status = 'loadmore';
					} else {
						this.status = 'nomore';
					}
				}
			});
		},
		clickbtn(flag, item) {
			this.toNav(`order/orderDetails?id=${item.id}`);
		},
		

		
		reset() {
			this.paging.page = 1;
			this.list = [];
		},
		clickTab(e) {
			this.reset();
			this.current = e.index;
			this.init();
		}
	}
};
</script>

<style lang="less" scoped>
.myOrder {
	.container {
		padding: 24rpx 32rpx;
	}
}
</style>
